
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title> 地理信息编辑 </title>
  <link rel="stylesheet" type="text/css" href="/css/style.css" />

  <style type="text/css">
    *, body {
      margin: 0px;
      font-family: '微软雅黑',serif;
    }
  </style>
  <script src="/js/jquery-1.10.2.min.js"></script>
  <script src="/js/jquery.form.js"></script>
  <script src="/js/generic.js"></script>
</head>

<body>

<table class="maintable">
  <tr>
    <td class="rightmaintd" valign="top">
      <div class="searchdiv">
        <a href="/dlxx">&lt; 返回</a>
        <div class="rightsearchdiv"><!-- name --></div>
      </div>
      <table class="leftrighttable" border="0">
        <tr>
          <td class="lefttdtable" width="50%" valign="top">
            <table cellpadding="6">
              <tr>
                <td class="tdname">省</td>
                <td><input type="text" id="sheng" class="textinput" maxlength="50"></td>
              </tr>
              <tr>
                <td class="tdname">市/县</td>
                <td><input type="text" id="shi" class="textinput" maxlength="50"></td>
              </tr>
              <tr>
                <td class="tdname">地域</td>
                <td><input type="text" id="diyu" class="textinput" maxlength="50"></td>
              </tr>

              <tr>
                <td class="tdname">流域</td>
                <td><input type="text" id="liuyu" class="textinput" maxlength="50"></td>
              </tr>

            </table>
          </td>
          <td class="righttdtable" width="50%" valign="top"></td>
        </tr>

      </table>

      <div style="margin-left: 125px">
        <input type="button" value="创 &nbsp; &nbsp; 建" class="baocunbtn" id="Sbutton">
        <span id="lrxx"></span>
      </div>

    </td>
  </tr>
</table>


</body>
</html>
<script type="text/javascript">
  // 保存按钮点击事件处理函数
  var saveButton = document.getElementById('Sbutton');
  saveButton.addEventListener('click',() => {
    // 获取输入框中的数据
    var shengValue = document.getElementById('sheng').value;
    if(shengValue==""){
      alert("请输入省名！");
      return;
    }
    var shiValue = document.getElementById('shi').value;
    if(shiValue==""){
      alert("请输入市/县名！");
      return;
    }
    var diyuValue = document.getElementById('diyu').value;
    var liuyuValue = document.getElementById('liuyu').value;

    // 创建要发送的数据对象
    var data = {
      sheng: shengValue,
      shi: shiValue,
      diyu: diyuValue,
      liuyu: liuyuValue,
    };
    // 发送 POST 请求
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/dlxx/', true);
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.onreadystatechange = function() {
      if (xhr.readyState === 4 && xhr.status === 200) {
        // 请求完成并成功处理后的回调函数
        console.log('数据已成功发送至后端');
        alert("创建成功！");
        window.location.href="/dlxx";
      }
    };
    xhr.send(JSON.stringify(data));
  });

</script>